/**
 * Notes: 会场后台管理模块业务逻辑
 * Ver : CCMiniCloud Framework 2.0.1 ALL RIGHTS RESERVED BY cclinux0730 (wechat)
 * author: bqchen
 * Date: 2022-06-24 07:48:00 
 */

const BaseBiz = require('../../../comm/biz/base_biz.js');
const projectSetting = require('../public/project_setting.js');
const formSetHelper = require('../../../cmpts/public/form/form_set_helper.js');

class AdminRoomBiz extends BaseBiz {
	static initFormData(id = '') {
		//let cateIdOptions = ActivityBiz.getCateList();
		return {
			id,
			//cateIdOptions,
			fields: projectSetting.ROOM_FIELDS,
			formTitle: '',
			// formCateId: (cateIdOptions.length == 1) ? cateIdOptions[0].val : '',
			formOrder: 9999,
			formSeatCnt: 50,
			formAddress: '',
			formAddressGeo: {
				address: '',
				latitude: 0,
				longitude: 0,
				name: ''
			},
			formForms: [],
			// formJoinForms: formSetHelper.initFields(projectSetting.ACTIVITY_JOIN_FIELDS),
		}
	}
	static getSeatInfo(val) {
		let seatCnt = 0;
		let seatList = [];
		for(let k = 0; k < (val || []).length; k ++) {
			let arr = (val[k].title || '').split('|')
			seatCnt += arr.length
			seatList = seatList.concat(arr)
		}
		return {
			seatCnt,
			seatList
		}
	}
	static selectLocation(that) {
		let callback = function (res) {
			if (!res || !res.name || !res.address || !res.latitude || !res.longitude){
				return;
			}

			console.log("selectLocation callback: " + JSON.stringify(res))
			let formAddress = res.address + '  ' + res.name;
			let formAddressGeo = {};
			formAddressGeo.name = res.name;
			formAddressGeo.address = res.address;
			formAddressGeo.latitude = res.latitude;
			formAddressGeo.longitude = res.longitude;
			that.setData({
				formAddressGeo,
				formAddress
			});
		}
		if (that.data.formAddressGeo && that.data.formAddressGeo.latitude > 0) {
			wx.chooseLocation({
				latitude: that.data.formAddressGeo.latitude,
				longitude: that.data.formAddressGeo.longitude,
				success: function (res) {
					callback(res);
				}
			})
		} else {
			wx.chooseLocation({
				success: function (res) {
					callback(res);
				},
				fail: function (err) {
					console.log(err);
				}
			})
		}
	}
}

AdminRoomBiz.CHECK_FORM = {
	title: 'formTitle|must|string|min:2|max:50|name=会场标题',
	// cateId: 'formCateId|must|id|name=分类',
	order: 'formOrder|must|int|min:0|max:9999|name=排序号',
	seatCnt: 'formSeatCnt|must|int|name=会场座位数量',
	seatList: 'formSeatList|must|array|name=会场座位列表',
	address: 'formAddress|must|string|name=会场地点',
	addressGeo: 'formAddressGeo|must|object|name=会场地点GEO',
	forms: 'formForms|must|array|name=会场表单',
};

module.exports = AdminRoomBiz;